package org.example.wikwok.service.impl;

import org.example.wikwok.service.CommentService;
import org.example.wikwok.service.InteractionService;
import org.example.wikwok.service.NotificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.management.Notification;

//处理消息通知的逻辑，如点赞、评论或关注通知。
//提供通知的创建和查询接口。
@Service
public class NotificationServiceImpl implements NotificationService {
    @Autowired
    private CommentService commentService;
    @Autowired
    private InteractionService interactionService;

    //处理点赞通知
    @Override
    public void handleThumbUpNotification(String userId, String videoId) {
        //查找该用户对该视频的点赞记录
        boolean isThumbUp = interactionService.isThumbUp(userId, videoId);
        if (isThumbUp) {
            //如果用户已经点赞过，则不再发通知
            return;
        }
        //如果用户没有点赞过，则创建点赞通知
        interactionService.createThumbUpNotification(userId, videoId);
    }

    //处理评论通知
    @Override
    public void handleCommentNotification(String userId, String videoId, String commentId) {
        //查找该用户对该评论的点赞记录
        boolean isThumbUp = interactionService.isThumbUp(userId, commentId);
        if (isThumbUp) {
            //如果用户已经点赞过，则不再发通知
            return;
        }
        //如果用户没有点赞过，则创建点赞通知
        interactionService.createThumbUpNotification(userId, commentId);
    }

    //处理关注通知
    @Override
    public void handleFollowNotification(String userId, String followerId) {
        //查找该用户是否已经关注了followerId
        boolean isFollowed = interactionService.isFollowed(userId, followerId);
        if (isFollowed) {
            //如果用户已经关注了followerId，则不再发通知
            return;
        }
        //如果用户没有关注followerId，则创建关注通知
        interactionService.createFollowNotification(userId, followerId);
    }

    //查询用户的通知列表
    @Override
    public Notification[] queryNotificationList(String userId) {
        //查询该用户的通知列表
        return interactionService.queryNotificationList(userId);
    }
}
